<?php

namespace gylApi\modules\guest\controllers;

use gylApi\models\db\Adminers;
use common\components\fast_api\Controller;

class SiteController extends Controller
{
    /**
     * 登录
     * @desc 登录
     * @param string $mobile 手机号
     * @param string $password 密码
     * @return mixed
     */
    public function actionLogin($mobile, $password)
    {
//        $password = md5($password);
//        $password = md5($password);
        $adminer = Adminers::findOne(['mobile' => $mobile]);
        if (!$adminer || !$adminer->validatePassword($password)){
            return $this->apiError("账号或密码错误");
        }
        if ($adminer->status !== $adminer::STATUS_ACTIVE) {
            return $this->apiError("用户已被封禁");
        }
        $respContArr =   \Yii::$app->gylApiTool->setTokenKey($adminer->token, $adminer->key)->request('/rbac/adminer/auth-info');
        if ($respContArr['code'] != 200) {
            return $this->apiError("用户异常");
        }
        return $this->apiSuccess([
            'info' => $respContArr['data']['auth-info'],
        ]);
    }
}
